// 获取个人信息*********************

function userInfo() {
    //    var a = localStorage.getItem('token')
    $.ajax({
        url: '/my/user/userinfo',
        success: function (res) {
            console.log(res);
            if (res.status===0) {
                // 优先nickname then username
            // 优先pic then name的首字母
            var name = res.data.nickname || res.data.username;
            $('.username').html(name);
            if (res.data.user_pic) {
                $('.layui-nav-img').attr('src', res.data.user_pic).show()
                $('.user-avatar').hide()
            } else {
                var first = name.substr(0, 1).toUpperCase();
                $('.user-avatar').text(first).css('display','inline-block');
            }
 
            }           
        },
        // complete: function (xhr) {
        //     console.log(xhr);
        //     if (xhr.responseJSON && xhr.responseJSON.status === 1 && xhr.responseJSON.message === '身份认证失败！') {
        //         localStorage.removeItem('token');
        //         location.href='./login.html'
        //     }
        // },
        // headers: {
        //     'authorization': localStorage.getItem('token')
        // }
    })
}
userInfo();
// 退出登录*******************
$('#logout').on('click', function (e) {
    e.preventDefault();
    layer.confirm('确定么?', {icon: 3, title:'提示'}, function(index){
        //do something     
        localStorage.removeItem('token');
        location.href = './login.html';
        layer.close(index);
    });
    
})